package com.itheima.tlias.controller;

import com.itheima.tlias.common.Result;
import com.itheima.tlias.utils.AliyunOssUitls;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传功能
 * @author
 * @version 1.0.1
 * @date 2023-04-08 16:03:19
 */
@RestController
@Slf4j
public class UploadController {

    @Autowired
    private AliyunOssUitls aliyunOssUitls;

    @PostMapping("/upload")
    public Result upload(@RequestParam(name = "image") MultipartFile file){
        log.warn("{}", file);
        String imgUrl = null;
        try {
            imgUrl = aliyunOssUitls.uploadImg(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success(imgUrl);
    }

}
